// pages/zxlb/zxlb.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zxlist: [],
    zxlist2: [],
    pageNumber: 2,
    totalPage: 0,
    
    hasmoreData: true,//更多数据
    hiddenloading: true,//加载中

    indicatorDots: true,  //是否显示面板指示点
    autoplay: true,      //是否自动切换
    interval: 3000,       //自动切换时间间隔
    duration: 1000,       //滑动动画时长
    inputShowed: false,
    inputVal: ""
  },
  //资讯详情
  zxbind: function (e) {
    console.log(e);
    wx.navigateTo({
      url: '/pages/zx/zx?id=' + e.currentTarget.id,
    })
  },
  sl: function () {
    var zxlists = this.data.zxlist;
    var that = this;
    if (that.data.hasmoreData == false) {
      that.setData({ hiddenloading: true })
      return;
    }
    // that.data.zxlist.pageNumber = that.data.pageNumber;
    // that.data.zxlist.pageSize = that.data.pageSize;
    // app.globalData.request.postRequest(app.globalData.config.Url, that.data.zxlist, function (res) {
    console.log(that.data.pageNumber)
      wx.request({
        url: 'https://wwcxc.arksh.com/info/blog/list',
        data: {
          nid: 35,
          length: 4,
          pageNumber: that.data.pageNumber
        },
        method: 'GET',
        success: function (res) {
          console.log(res.data.totalPage);
          that.setData({
            totalPage: res.data.totalPage,
            zxlist: zxlists.concat(res.data.list),
            pageNumber: that.data.pageNumber + 1
          })
        }
      })
      if (that.data.totalPage <= 0 || that.data.pageNumber * that.data.pageSize >= that.data.totalPage) {
        that.setData({ hasmoreData: false, hiddenloading: true })
      }
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    
    //获取资讯
    wx.request({
      url: 'https://wwcxc.arksh.com/info/blog/list',
      data: {
        nid: 35,
        length: 4,
        pageNumber: 1
      },
      success: function (data) {

        console.log(data);
        that.setData({
          zxlist: data.data.list,
          zxlist2: data.data.list
        })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
    var that = this;
    console.log('加载更多');
    that.setData({ hiddenloading: false });
    that.sl();
    //  wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中” 
    //     title: '加载中',
    //     icon: 'loading',
    //     duration: 200
    //   })
    //  wx.request({
    //    url: 'https://wwcxc.arksh.com/info/blog/list',
    //     data: {
    //      nid: 35,
    //      length: 2,
    //      pageNumber: that.data.pageNumber+1
    //     },
    //     method: 'GET',
    //     success: function (res) {
    //       console.log(zxlists.concat(res.data.list)) //打印拼接之后数据
    //       console.log(res.data.lastPage)
    //       if(res.data.lastPage){
    //         that.setData({

    //           loadText: "无更多数据",
    //           loading: false,
    //         })

    //       }else{
    //         that.setData({
    //           loadText: "数据请求中",
    //           loading: true,
    //           zxlist: zxlists.concat(res.data.list),
    //           loadText: "加载更多",
    //           loading: false,
    //         })
    //       }
    //       
    //     }
    //  })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})